﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Basket
/// </summary>
public class Basket
{
    public List<CartItem> Items { get; private set; }

    public static readonly Basket Instance;

    static Basket()
    {
        // If the cart is not in the session, create one and put it there  
        // Otherwise, get it from the session  
        if (HttpContext.Current.Session["ASPNETShoppingCart"] == null)
        {
            Instance = new Basket();
            Instance.Items = new List<CartItem>();
            HttpContext.Current.Session["ASPNETShoppingCart"] = Instance;
        }
        else
        {
            Instance = (Basket)HttpContext.Current.Session["ASPNETShoppingCart"];
        }
    }

    // A protected constructor ensures that an object can't be created from outside  
    protected Basket() { }


    public void AddItem(Int64 postingID)
    {
        // Create a new item to add to the cart  
        CartItem newItem = new CartItem(postingID);

        // If this item already exists in our list of items, increase the quantity  
        // Otherwise, add the new item to the list  
        if (Items.Contains(newItem))
        {
            foreach (CartItem item in Items)
            {
                if (item.Equals(newItem))
                {
                  
                }
            }
        }
        else
        {
            Items.Add(newItem);
        }
    }

    public void RemoveItem(Int64 postingID)
    {
        CartItem removedItem = new CartItem(postingID);
        Items.Remove(removedItem);
    }



}